<template>
  <q-page class="cc-admin">
    <div>
      <q-table flat row-key="id" color="primary" class="cross_table" separator="cell" :columns="columns" :data="list" :pagination.sync="pagination"
        :visible-columns="group" :rows-per-page-options="[10, 20, 50, 100]" :selection="mobile ? 'none' : 'multiple'" :selected.sync="selected" @request="query">
        <template v-slot:top="table">
          <div class="row no-wrap full-width">
            <q-input clearable outlined dense placeholder="请输入关键字搜索" class="on-left" @input="query" debounce="500" v-model="key">
              <template #append>
                <q-btn flat round icon="search" color="primary" @click="query" :loading="loading">
                  <q-tooltip>搜索</q-tooltip>
                </q-btn>
              </template>
            </q-input>
            <q-space />
            <table-top-btns label="子系统管理" modelName="subsystem" :showAdd="true" :table="table" :selected="selected" :importing="importing" :exporting="exporting"
              :importExcelUrlFull="importExcelUrlFull" :columns="columns" @groupChange="groupChange" @add="add" @importExcel="importExcel"
              @exportExcel="exportExcel" @showConfirm="showConfirm" />
          </div>
        </template>
        <template #body-cell-opt="props">
          <q-td :props="props" :auto-width="true">
            <cc-btn label="编辑" color="primary" icon="edit" @click="edit(props.row)"> <q-tooltip>编辑</q-tooltip></cc-btn>
            <btn-del label="角色" @confirm="del(props.row)" />
          </q-td>
        </template>
      </q-table>
    </div>
    <cc-dialog ref="dialog" :title="`${editType}子系统`" @submit="submit">
      <div class="col-12">
        <h5>
          <q-icon name="star" color="red" />编码：
        </h5>
        <q-input outlined dense v-model="form.code" type="text" clearable :rules="[requiredTest]" />
      </div>
      <div class="col-12">
        <h5>
          <q-icon name="star" color="red" />名称：
        </h5>
        <q-input outlined dense v-model="form.name" type="text" clearable :rules="[requiredTest]" />
      </div>
      <div class="col-12" >
        <h5>菜单图标：</h5>
        <q-input outlined dense v-model="form.icon">
          <template #prepend>
            <q-icon size="sm" :name="form.icon" />
          </template>
          <template #append>
            <q-btn round dense flat icon="search" color="primary">
              <q-menu>
                <q-btn round dense flat v-for="v in icons" :key="v" :icon="v" color="t-grey" @click="form.icon = v" />
              </q-menu>
            </q-btn>
          </template>
        </q-input>
      </div>
      <div class="col-12">
        <h5>排序</h5>
        <q-input outlined dense v-model="form.sort" type="text" clearable />
      </div>
      <div class="col-12">
        <h5>备注</h5>
        <q-input outlined dense v-model="form.remark" clearablerows="3" type="textarea" />
      </div>
    </cc-dialog>
    <confirm ref="confirmDialog" :msg="confirmMsg" @confirm="deleteBatch()" />
    <cc-loading :loading="loading" />
  </q-page>
</template>

<script>
import confirm from 'components/confirm';
import { IndexMixin } from 'boot/mixins';
import { requiredTest } from 'boot/inputTest';
import { getter } from 'boot/dictionary';

export default {
  name: 'SubSystem',
  mixins: [IndexMixin],
  components: {
    confirm,
  },
  data() {
    return {
      icons: getter('icon'),
      splitterModel: 50,
      QueryTreeList: [],
      ticked: [],
      initializeIds: [],
      columns: [
        {
          name: 'index',
          align: 'center',
          label: '序号',
          field: 'index',
          headerClasses: 'cc-table-index',
        },
        {
          name: 'code', align: 'center', label: '编码', field: 'code',
        },
        {
          name: 'name', align: 'center', label: '名称', field: 'name',
        },
        {
          name: 'opt', align: 'center', label: '操作', field: 'opt',
        },
      ],
      url: {
        list: '/sys/subsystem/list',
        add: '/sys/subsystem/add',
        edit: '/sys/subsystem/edit',
        delete: '/sys/subsystem/delete',
        deleteBatch: '/sys/subsystem/deleteBatch',
        exportXlsUrl: '/sys/subsystem/exportXls',
        importExcelUrl: '/sys/subsystem/importExcel',
      },
    };
  },

  methods: {
    requiredTest,
    reset() {
      this.form = {
        code: '',
        name: '',
        icon: '',
        sort: '',
        remark: '',
      };
    },
    add() {
      this.editType = '新建';
      this.reset();
      this.$refs.dialog.show();
    },
    initDict() {
      this.$axios.get('/sys/dictItem/selectItemsByDefId?defId=sysDepart').then((r) => {
        this.sysDepart = r;
      });
    },
  },
  mounted() {
    this.initDict();
  },
};
</script>

<style lang="stylus"></style>
